package com.xiaoma.tpo.dao;

import java.util.List;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.ChChapter;
import com.xiaoma.tpo.domain.UserWinNum;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

/**
 * Created by Owner on 2015/5/12.
 */
@Repository
public class UserWinNumDao extends BaseDaoImpl<UserWinNum>{
    private static final Logger LOG = LoggerFactory.getLogger(UserWinNumDao.class);
    
    public int getWinNUmByUser(int userid){
        int count = 0;
        String sql = "select SUM(activity_id) from user_win_num where user_id="+userid;
        count = jdbcTemplate.queryForInt(sql);
        return count;
    }
    
    @SuppressWarnings("unchecked")
    public List<UserWinNum> findByUserId(int userId) {
        String sql = "SELECT * FROM user_win_num WHERE user_id = ? order by id desc";
        LOG.info("SQL:{} PARAMS:{}", sql, userId);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(UserWinNum.class, getNameHandler()), userId);
        return (List<UserWinNum>)result;
    }
}
